package cn.zwk.drawing.domain.diagram.model;

import lombok.Data;
import lombok.Builder;
import java.util.List;
import java.util.Map;

/**
 * 图表节点领域实体
 */
@Data
@Builder
public class DiagramNode {
    
    /**
     * 节点唯一标识
     */
    private String nodeId;
    
    /**
     * 节点显示名称
     */
    private String name;
    
    /**
     * 节点类型
     */
    private NodeType type;
    
    /**
     * 节点描述
     */
    private String description;
    
    /**
     * 节点能力列表
     */
    private List<NodeCapability> capabilities;
    
    /**
     * 节点样式属性
     */
    private NodeStyle style;
    
    /**
     * 节点位置信息（渲染后填充）
     */
    private NodePosition position;
    
    /**
     * 节点扩展属性
     */
    private Map<String, Object> properties;
    
    /**
     * 检查节点是否有指定能力
     */
    public boolean hasCapability(String capabilityId) {
        if (capabilities == null) return false;
        return capabilities.stream()
                .anyMatch(cap -> capabilityId.equals(cap.getId()));
    }
    
    /**
     * 获取指定能力
     */
    public NodeCapability getCapability(String capabilityId) {
        if (capabilities == null) return null;
        return capabilities.stream()
                .filter(cap -> capabilityId.equals(cap.getId()))
                .findFirst()
                .orElse(null);
    }
    
    /**
     * 节点类型枚举
     */
    public enum NodeType {
        SERVICE("service", "服务"),
        DATABASE("database", "数据库"),
        GATEWAY("gateway", "网关"),
        CACHE("cache", "缓存"),
        QUEUE("queue", "消息队列"),
        EXTERNAL("external", "外部系统");
        
        private final String code;
        private final String description;
        
        NodeType(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() { return code; }
        public String getDescription() { return description; }
    }
}